import {userLogin,
    sendVerficationCode,
    getInvitationByPhone
} from '@/api/loginApi'
const login = {
    namespaced: true,
    state: {
        resultData: localStorage.resultData ? JSON.parse(localStorage.resultData) : '',
        userInfo: localStorage.userInfo ? JSON.parse(localStorage.userInfo) : ''
    },
    getters: {
        
    },
    mutations: { 
        setUserInfo (state, userInfo) {
            state.userInfo = userInfo
            localStorage.userInfo = JSON.stringify(userInfo)
        },
        setResultData (state, resultData) {
            debugger
            state.resultData = resultData
            localStorage.resultData = JSON.stringify(resultData)
        },
    },
    actions: { 
        UserLogin ({state, commit, dispatch}, params) {
            return new Promise((resolve, reject) => {
                userLogin(params).then(res => {
                    resolve(res)
                })
            })
          },
          SendVerficationCode ({state, commit, dispatch}, params) {
            return new Promise((resolve, reject) => {
                sendVerficationCode(params).then(res => {
                    resolve(res)
                })
            })
          },
          GetInvitationByPhone ({state, commit, dispatch}, params) {
            return new Promise((resolve, reject) => {
                getInvitationByPhone(params).then(res => {
                    resolve(res)
                })
            })
          }
    }
}
export default login
